package com.efuture.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @ClassNAME JdbcInsertData
 * @Description 使用jdbc向 account 表插入一条数据
 * @Author zhaoshanshan
 * @Date 2021/9/19 5:59 下午
 * @Version 1.0
 */
public class JdbcInsertData {

    public static void main(String[] args) {
        Connection coon = null;
        Statement stmt = null;
        try{
            //注册驱动
            Class.forName("com.mysql.jdbc.Driver");
            //获取数据库连接对象 Connection
            coon = DriverManager.getConnection("jdbc:mysql://localhost:3306/db3", "root", "zhaoss");
            //定义sql
            String sql = "insert into account values(null,'zhaoshan',5000)";
            //获取执行Sql的对象
            stmt = coon.createStatement();
            //执行sql
           int count =  stmt.executeUpdate(sql);
           //打印受影响的返回行
            System.out.println("受影响的返回行数"+count);
        }catch (Exception e){
            e.printStackTrace();
        }
        finally {
            //释放资源
            if(null!=coon){
                try {
                    coon.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            if(null!=stmt){
                try {
                    stmt.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}